#version 450 core

layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;

layout(std140, binding = 0) uniform _TransformMatrix
{
    mat4 _MVMatrix;
    mat4 _ViewMatrix;
    mat4 _ProjMatrix;
} transformMatrix;

layout(std140, binding = 1) uniform _Light
{
    vec4 position;
    vec4 ambient;
    vec4 diffuse;
    vec4 specular;
} light;

out V2F
{
    vec3 p;
    vec3 n;
    vec3 l;
    vec3 v;
} v2f;

void main()
{
    // calc in view-space
    v2f.p = vec3(transformMatrix._MVMatrix * position);
    v2f.n = mat3(transformMatrix._MVMatrix) * normal;
    v2f.l = vec3(transformMatrix._ViewMatrix * light.position) - v2f.p;
    v2f.v = -v2f.p;

    gl_Position = transformMatrix._ProjMatrix * transformMatrix._MVMatrix * position;
}
